<template>
  <div id="index">
    <div class="app-container" id="container">
      <el-form ref="form" :model="form" :rules="rules" label-width="120px" label-position="right">
        <div class="product-div">
          <div class="product-header big_title_style">
            基本信息
          </div>

          <el-form-item label="等级名称" prop="levelName">
            <el-input show-word-limit maxlength="10" style="width: 220px;" v-model="form.levelName"
                      placeholder="输入等级名称" />
            <!-- <el-input v-model="form.levelName" placeholder="输入等级名称" /> -->
          </el-form-item>
          <el-form-item label="级别图标">
            <imageUpload v-model="form.levelIcon" />
          </el-form-item>
          <el-form-item label="等级背景">
            <div class="elradio">
              <el-radio v-model="form.caedFace" label="0">背景颜色
              </el-radio>
              <br />
              <el-radio v-model="form.caedFace" label="1">背景图片
              </el-radio>
              <div class="block" v-if="form.caedFace == 0">
                <el-color-picker v-model="bgcolor"></el-color-picker>
              </div>
              <imageUpload v-if="form.caedFace == 1" v-model="form.levelImage" />
            </div>
          </el-form-item>
          <el-form-item label="付费规则">
            <el-table class="ruleTable" :data="paymentRuless" border style="width: 600px">
              <el-table-column align="center" label="有效期" prop="periodValidity"></el-table-column>
              <el-table-column align="center" prop="price" label="价格">
              </el-table-column>
              <el-table-column align="center" prop="receiveNumber" label="操作">
                <template slot-scope="scope">
                  <el-link type="danger" :underline="false" @click="handlepaymentr(scope.$index, scope.row)">删除</el-link>
                  <!-- <span
                        style="color:rgb(0, 175, 255)"
                        @click="handlepaymentr(scope.$index, scope.row)"
                        >编辑</span
                      > -->
                </template>
              </el-table-column>
            </el-table>
            <div style="margin-top:10px" v-if="isaddrule == true">
            <!-- <div style="margin-top:10px"> -->
              <el-select v-model="periodValiditys" placeholder="请选择" size="small" class="input-rule"
                         style="width:100px">
                <el-option v-for="(item, index) in paymentRules" :key="index" :label="item.periodValidity"
                           :value="item.periodValidity" />
              </el-select>
              <el-input style="width:100px;margin: 0 65px 0 30px" size="small" placeholder="价格" v-model="price">
              </el-input>
              <el-link type="primary" :underline="false" style="color:rgb(0, 175, 255)" @click="addPaymentRules">保存</el-link>
            </div>
            <el-button size="mini" @click="addrule" v-if="isaddrule == false" style="margin-top: 10px;">添加规则</el-button>
          </el-form-item>
          <div v-if="form.caedFace == 0" class="bgcard" :style="{
                            background: bgcolor,
                          }">
            <div class="font-a" v-if="form.levelName">
              {{ form.levelName }}
            </div>
            <div class="font-a" v-else>Vip{{ form.customerGrade }}</div>
            <div class="font-b">
              最小积分 <span>{{ form.minScore }}</span><br />
              粉丝数量 <span>{{ form.fansNumber }}</span><br />
              业绩 <span>{{ form.performance }}</span><br />
            </div>
            <div class="font-c"></div>
          </div>
          <div v-if="form.caedFace == 1">
            <div class="bgcard" :style="{
                                        background: bgcolor,
                                      }">
              <div class="font-a" v-if="form.levelName">
                {{ form.levelName }}
              </div>
              <div class="font-a" v-else>Vip{{ form.customerGrade }}</div>
              <div class="font-b">
                最小积分 <span>{{ form.minScore }}</span><br />
                粉丝数量 <span>{{ form.fansNumber }}</span><br />
                业绩 <span>{{ form.performance }}</span><br />
              </div>
              <div class="font-c"></div>
            </div>
            <div class="bgcard" :style="{
                                        backgroundImage: 'url(' + form.levelImage + ')',
                                        backgroundSize: '100% 100%',
                                      }">
              <div class="font-a" v-if="form.levelName">
                {{ form.levelName }}
              </div>
              <div class="font-a" v-else>Vip{{ form.customerGrade }}</div>
              <div class="font-b">
                最小积分 <span>{{ form.minScore }}</span><br />
                粉丝数量 <span>{{ form.fansNumber }}</span><br />
                业绩 <span>{{ form.performance }}</span><br />
              </div>
              <div class="font-c"></div>
            </div>
          </div>
        </div>

        <div class="product-div">
          <div class="product-header big_title_style">
            分拥比例
          </div>
          <el-form-item label="直接分拥比例" prop="directPointsPointsStr">
            <el-input  maxlength="5" style="width: 220px;" v-model="form.directPointsPointsStr"
                       placeholder="输入直接分拥比例" >
              <i slot="suffix" style="font-style:normal;margin-right: 10px;">%</i>
            </el-input>
          </el-form-item>
          <el-form-item label="间接分拥比例"  prop="indirectPointsPointsStr">
            <el-input  maxlength="5" style="width: 220px;" v-model="form.indirectPointsPointsStr"
                       placeholder="输入间接分拥比例" >
              <i slot="suffix" style="font-style:normal;margin-right: 10px;">%</i>
            </el-input>
          </el-form-item>
          <el-form-item label="自购分拥比例"  prop="selfbuyPointsPointsStr">
            <el-input  maxlength="5" style="width: 220px;" v-model="form.selfbuyPointsPointsStr"
                       placeholder="输入自购分拥比例" >
              <i slot="suffix" style="font-style:normal;margin-right: 10px;">%</i>
            </el-input>
          </el-form-item>
        </div>

        <div class="product-div-two">
          <div class="product-header big_title_style">
            会员权益
          </div>

          <el-form-item label="权益">
            <!-- <el-checkbox-group v-model="form.customerLevelPrivleageVos"> -->
            <el-checkbox style="display: block" v-for="(item, index) in hashs" :label="item.privleageShowName"
                         :key="index" :checked="item.privilegeStatus" @change="(val) => privilege(val, item, index, hashs)">
              <span>{{ item.privleageShowName }}</span>
              <div style="display: inline-block; margin-left: 10px" v-if="
                                item.platformUnit != null && item.privilegeStatus == true
                               ">
                <el-input @blur="privilegeOnInputBlur(item.privilegeValue)" v-model="item.privilegeValue" size="small"
                          placeholder="填写数字" @keyup.enter="search" @input="search"></el-input>
                <span class="Unitdiv">
                  {{ item.platformUnit }}
                </span>
              </div>
            </el-checkbox>
            <!-- </el-checkbox-group> -->
            <p v-if="loadingmore == 1" @click="more" style="color: rgb(0, 175, 255)">
              加载更多
            </p>
          </el-form-item>



          <div class="dw" align="center">
            <el-button @click="Formcancel" style="margin-top: 15px;">取消</el-button>
            <el-button type="primary" @click="submitForm" style="margin-top: 10px;">保存</el-button>
          </div>
        </div>
      </el-form>

      <div class="dw">
        <el-button @click="Formcancel">返回</el-button>
        <el-button type="primary" @click="submitForm">确 定</el-button>
      </div>


    </div>
  </div>

</template>

<script>
import {
  getLevelInfo,
  UpdateStartStatus,
  levelInfoDetail,
  delLevel,
  saveLevelPrivileageInfo,
  UpdateLevelPrivileageInfo,
  PrivileageInfo,
} from "@/api/customer/level";
import {
  getUploadToken
} from "@/api/monitor/file";
import Vue from "vue";
import selGift from "@/components/Activity/selGift";
import selCoupon from "@/components/Activity/selCoupon";
import ImageUpload from "@/components/ImageUpload/levelImage";

let poins = (rule, value, callback) => {
  const reg = /^\d*\.{0,1}\d{0,1}$/
  if (!value && Number(value)!=0) {
    callback(new Error('请输入比例'))
  } else if (!Number(value) && Number(value)!=0) {
    callback(new Error('请输入数字值'))
  } else {
    if (reg.test(value)) {
      callback()
    } else {
      callback(new Error('小数点后最多只能输入一位'))
    }
  }
}
export default {
  name: "freePatternUpdate",
  components: {
    selGift,
    ImageUpload,
    selCoupon
  },
  props: {

  },
  data() {
    return {
      openR: false,
      openC: false,
      levelColor: '',
      resdata: [],
      isaddrule: false,
      price: "",
      periodValiditys: "",
      paymentRuless: [],
      paymentRules: [{
        periodValidity: "1个月",
      },
        {
          periodValidity: "3个月",
        },
        {
          periodValidity: "12个月",
        },
      ],
      coupon: false,
      Giftgiving: false,
      listPrivilegedatas: [],
      listPrivilegedata: [],
      hashs: [],
      hash: [],
      loadingmore: 1,
      loadingmore2: 1,
      //默认显示条数
      cou: 3,
      giftsNumber: "",
      productObj: {
        giftUid: "",
        giftName: "",
        productImg: "",
        stockNumber: "",
        receiveNumber: "",
      },
      infoList: [],
      infoList2: [],
      privilegeUid: "",
      property: [],
      giftUids: [],
      selUids: [],
      selList: [],
      levelPrivileageGives: [],
      titleg: "",
      openg: false,
      isIndeterminate: false,
      inputone: "",
      listPrivilege: null,
      bgcolor: '#87CEEB',
      itemcolor: "",
      caedFace: "0",
      visible: false,
      previewImg: "",
      uploadImgUrl: "https://upload-z2.qiniup.com",
      upload_domain: "",
      uploadData: {
        token: "",
        key: ""
      },
      show: false,
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        ShowName: [{
          required: true,
          message: "请输入内容",
          trigger: "blur"
        }],
        levelName: [{
          required: true,
          message: "请输入内容",
          trigger: "blur"
        }],
        minScore: [{
          required: true,
          message: "请输入内容",
          trigger: "blur"
        }],
        payRule: [{
          required: true,
          message: "付费规则不能为空",
          trigger: "blur"
        }],
        directPointsPointsStr: [{
          required: true,
          validator: poins,
          trigger: 'blur'
        }],
        indirectPointsPointsStr: [{
          required: true,
          validator: poins,
          trigger: 'blur'
        }],
        selfbuyPointsPointsStr: [{
          required: true,
          validator: poins,
          trigger: 'blur'
        }],
        fansNumber: [{
          required: true,
          message: "请输入内容",
          trigger: "blur"
        }, ],
        performance: [{
          required: true,
          message: "请输入内容",
          trigger: "blur"
        }, ],
      },
      checkExceptRisk: [],
    }
  },
  created() {
    let $this = this;
    var levelId = $this.$route.params && $this.$route.params.levelId;
    if (levelId != null) {
      this.reset();
      // const levelId = row.levelId || this.ids;
      levelInfoDetail(levelId).then((response) => {
        this.form = response.customerLevel;
        this.bgcolor = this.form.levelColor;
        this.open = true;
        this.title = "修改客户等级";
        this.hash = [];
        this.listPrivilegedata = [];
        let giveobjs = new Array();
        let giveobjs2 = new Array();
        for (let i = 0; i < this.form.customerLevelPrivleageVos.length; i++) {
          if (
            this.form.customerLevelPrivleageVos[i].levelPrivileageGives != null
          ) {
            let giveList =
              this.form.customerLevelPrivleageVos[i].levelPrivileageGives;
            giveList.forEach((item) => {
              if (item.giveType == "coupon") {
                let giveobj2 = new Object();
                giveobj2.couponTypeName = item.giveName;
                giveobj2.couponUid = item.giveGiftId;
                giveobj2.couponNumber = item.giveNumber;
                giveobj2.stock = item.giveSumNumber;
                giveobjs2.push(giveobj2);
              }
              if (item.giveType == "gift") {
                let giveobj = new Object();
                giveobj.giftName = item.giveName;
                giveobj.giftUid = item.giveGiftId;
                giveobj.giftsNumber = item.giveNumber;
                giveobj.stockNumber = item.giveSumNumber;
                giveobjs.push(giveobj);
              }
            });
            this.infoList2 = giveobjs2;
            this.infoList = giveobjs;
          }
        }

        this.paymentRuless.push(this.form.paymentRules);
        this.paymentRules.forEach((item, index) => {
          if (item.periodValidity == this.form.paymentRules.periodValidity) {
            this.paymentRules.splice(index, 1);
          }
        });
        for (let i = 0; i < this.form.customerLevelPrivleageVos.length; i++) {
          this.checkExceptRisk.push(this.form.customerLevelPrivleageVos[i]);
          if (this.checkExceptRisk[i].privilegeStatus == true) {
            if (this.checkExceptRisk[i].privleageName == "coupon") {
              this.coupon = true;
            }
            if (this.checkExceptRisk[i].privleageName == "gift") {
              this.Giftgiving = true;
            }
          }
        }
        for (let i = 0; i < this.form.customerLevelPrivleageVos.length; i++) {
          if (this.form.customerLevelPrivleageVos[i].isUpgrade == 0) {
            this.hash.push(this.form.customerLevelPrivleageVos[i]);
          }
        }
        for (let i = 0; i < this.form.customerLevelPrivleageVos.length; i++) {
          if (this.form.customerLevelPrivleageVos[i].isUpgrade == 1) {
            this.listPrivilegedata.push(this.form.customerLevelPrivleageVos[i]);
          }
        }

        if (this.loadingmore == 1) {
          if (this.hash.length >= 3) {
            this.hashs = this.hash.slice(0, this.cou);
          }
        } else if (this.loadingmore == 0) {
          this.hashs = this.hash;
        }
        if (this.loadingmore2 == 1) {
          if (this.listPrivilegedata.length >= 3) {
            this.listPrivilegedatas = this.listPrivilegedata.slice(0, this.cou);
          }
        } else if (this.loadingmore2 == 0) {
          this.listPrivilegedatas = this.listPrivilegedata;
        }
      });
    } else {
      this.getlistPrivilege();
    }
  },
  methods: {
    //输入框失去焦点事件
    privilegeOnInputBlur(privilegeValue) {
      let reg = /^((0\.[1-9]{1})|(([1-9]{1})(\.\d{1})?))$/;
      if (!reg.test(privilegeValue)) {
        this.$message.error("请输入整数或小数后一位")
      }
    },
    upgradeOnInputBlur(privilegeValue) {
      let reg = /^[0-9]{1,8}$/;
      if (!reg.test(privilegeValue)) {
        this.$message.error("请输入八位整数")
      }
    },
    multipleSelection(data) {
      this.openR = false
      this.infoList = data;
      this.infoList.forEach(i => {
        this.$set(i, 'giftsNumber', 1)
      })
    },
    multipleSelection2(data) {
      this.openC = false
      this.infoList2 = data;
      this.infoList2.forEach(i => {
        this.$set(i, 'couponNumber', 1)
      })
    },
    toCloseBox() {
      this.openR = false;
    },
    toCloseBox2() {
      this.openC = false;
    },
    addrule() {
      if (this.paymentRuless.length) {
        this.isaddrule = false;
        this.$message.error("付费等级设置一个价格");
      } else {
        this.isaddrule = true
      }
    },
    addPaymentRules() {
      const reg = /^\d*\.{0,1}\d{0,1}$/;
      console.log()
      if (!reg.test(this.price)) {
        this.$message.error("价格请输入整数或小数后一位");
      }
      this.paymentRuless.push({
        periodValidity: this.periodValiditys,
        price: this.price
      });
      this.periodValiditys = ''
      this.price = ''
      this.isaddrule = false
      this.resdata = this.paymentRules
      for (let i = 0; i < this.paymentRules.length; i++) {
        for (let k = 0; k < this.paymentRuless.length; k++) {
          this.paymentRuless[k];
          if (this.paymentRules[i].periodValidity == this.paymentRuless[k].periodValidity) {
            this.paymentRules.splice(i, 1)
          }
        }
      }
    },
    search() {
      this.privilege();
    },
    more() {
      let hashdata = this.hash.slice(3);
      for (let i = 0; i < hashdata.length; i++) {
        this.hashs.push(hashdata[i]);
      }
      this.loadingmore = 0;
    },
    more2() {
      let listPrivilege = this.listPrivilegedata.slice(3);
      for (let i = 0; i < listPrivilege.length; i++) {
        this.listPrivilegedatas.push(listPrivilege[i]);
      }
      this.loadingmore2 = 0;
    },

    handlepaymentr(val, row) {
      // 模态框删除按钮
      this.$confirm("是否确认删除本条数据?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "info",
      }).then(() => {
        this.paymentRules.push(this.paymentRuless[val]);
        this.paymentRuless.splice(val, 1);
      });
      // this.paymentRuless = this.paymentRules;
    },
    handleDeleteser(val, row) {
      // 模态框删除按钮
      this.$confirm("是否确认删除本条数据?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "info",
      }).then(() => {
        this.infoList.splice(val, 1);
      });
    },
    addcoupon() {
      this.$forceUpdate()
      this.openC = true;
      this.$nextTick(() => {
        this.$refs["selTable2"].greet2(this.infoList2);
      });
    },
    addgift() {
      this.$forceUpdate()
      this.openR = true;
      this.$nextTick(() => {
        this.$refs["selTable"].greet(this.infoList);
      });

    },
    handleDeleteser2(val, row) {
      // 模态框删除按钮
      this.$confirm("是否确认删除本条数据?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "info",
      }).then(() => {
        this.infoList2.splice(val, 1);
      });
    },
    giftDate(v, d) {
      //
      // v.map((v) => {
      //   let p = this.productObj;
      //   this.productObj.giftUid = v.giftUid;
      //   this.productObj.productImg = v.productImg;
      //   this.productObj.giftName = v.giftName;
      //   this.productObj.receiveNumber = v.receiveNumber;
      //   this.productObj.stockNumber = v.stockNumber;
      //
      //   this.infoList.push(this.productObj);
      // });
      this.selUids = [];
      this.selList = [];
      this.selList = v;
      this.infoList = v;
      this.selUids.push(d);
      this.openg = false;
    },
    editLevelDia() {
      this.reset();
      this.paymentRuless = [];
    },
    unit(platformUnit) {
      for (let i = 0; i < this.checkExceptRisk.length; i++) {
        if (this.checkExceptRisk[i].platformUnit == platformUnit) {
          return true;
        }
      }
    },
    unit2(platformUnit) {
      for (let i = 0; i < this.checkExceptRisk.length; i++) {
        if (this.checkExceptRisk[i].platformUnit == platformUnit) {
          return true;
        }
      }
    },
    privilege(val, item, index, hashs) {
      if (item != null) {
        if (val == true) {
          if (item.privleageName == "coupon") {
            item.privilegeValue = "赠品";
            this.coupon = true;
          }
          if (item.privleageName == "gift") {
            item.privilegeValue = "赠品";
            this.Giftgiving = true;
          }
          this.checkExceptRisk.forEach((riskItem) => {
            if (riskItem.privleageName == item.privleageName) {
              riskItem.privilegeStatus = true;
            }
          });
          console.log(this.checkExceptRisk)
        }
        if (val == false) {
          if (item.privleageName == "coupon") {
            item.privilegeValue = null;
            this.coupon = false;
          }
          if (item.privleageName == "gift") {
            item.privilegeValue = null;
            this.Giftgiving = false;
          }

          // for (let i = 0; i < this.checkExceptRisk.length; i++) {
          //   if (item == this.checkExceptRisk[i]) {
          //     this.checkExceptRisk.splice(i, 1);
          //   }
          // }

          this.checkExceptRisk.forEach((riskItem) => {
            if (riskItem.privleageName == item.privleageName) {
              riskItem.privilegeStatus = false;
            }
          });
        }
        item.privilegeStatus = val;
        for (let i = 0; i < this.checkExceptRisk.length; i++) {
          if (this.checkExceptRisk[i].privleageName === item.privleageName) {
            this.checkExceptRisk[i] = item;
          }
        }

      }
    },
    privilege2(val, item, index, listPrivilegedatas) {
      if (item != null) {
        if (val == true) {
          if (item.privleageName == "coupon") {
            item.privilegeValue = "赠品";
            this.coupon = true;
          }
          if (item.privleageName == "gift") {
            item.privilegeValue = "赠品";
            this.Giftgiving = true;
          }
          this.checkExceptRisk.forEach((riskItem) => {
            if (riskItem.privleageName == item.privleageName) {
              riskItem.privilegeStatus = true;
            }
          });
          // this.checkExceptRisk.push(item);
        }
        if (val == false) {
          if (item.privleageName == "coupon") {
            item.privilegeStatus = false;
            item.privilegeValue = "赠品";
            this.coupon = false;
            this.infoList2 = [];
          }
          if (item.privleageName == "gift") {
            item.privilegeStatus = false;
            item.privilegeValue = "赠品";
            this.Giftgiving = false;
            this.infoList = [];
          }

          for (let i = 0; i < this.checkExceptRisk.length; i++) {
            if (item == this.checkExceptRisk[i]) {
              if (this.checkExceptRisk[i].platformUnit == this.unitss) {
                this.unitss = null;
              }
              // this.checkExceptRisk.splice(i, 1);
            }
          }

          this.checkExceptRisk.forEach((riskItem) => {
            if (riskItem.privleageName == item.privleageName) {
              riskItem.privilegeStatus = false;
            }
          });

          console.log(this.checkExceptRisk)
        }
        item.privilegeStatus = val;
        for (let i = 0; i < this.checkExceptRisk.length; i++) {
          if (this.checkExceptRisk[i].privleageName === item.privleageName) {
            this.checkExceptRisk[i] = item;
          }
        }
      }
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        levelId: null,
        platformId: null,
        customerGrade: null,
        customerPattern: null,
        levelName: null,
        levelColor: null,
        levelIcon: null,
        minScore: null,
        fansNumber: null,
        performance: null,
        customerNumber: null,
        ruleId: null,
        dataStatus: "0",
        createTime: null,
        updateTime: null,
        createUser: null,
        updateUser: null,
        gradeprivilegeId: null,
        startStatus: "0",
        directPointsPoints: null,
        indirectPointsPoints: null,
        selfbuyPointsPoints: null,
      };
      this.resetForm("form");
    },
    getlistPrivilege() {
      PrivileageInfo().then((res) => {
        console.log(res);

        this.form = res;
        this.hash = [];
        this.listPrivilegedata = [];
        res.customerLevelPrivleageVos.forEach((item) => {
          if (item.isUpgrade == 0) {
            this.hash.push(item);
          } else {
            this.listPrivilegedata.push(item);
          }
          this.checkExceptRisk.push(item);
        });
        // for (let i = 0; i < this.form.customerLevelPrivleageVos.length; i++) {
        //   if (this.form.customerLevelPrivleageVos[i].isUpgrade == 0) {
        //     this.hash.push(this.form.customerLevelPrivleageVos[i]);
        //   }
        // }
        // for (let i = 0; i < this.form.customerLevelPrivleageVos.length; i++) {
        //   if (this.form.customerLevelPrivleageVos[i].isUpgrade == 1) {
        //     this.listPrivilegedata.push(this.form.customerLevelPrivleageVos[i]);
        //   }
        // }

        if (this.loadingmore == 1) {
          if (this.hash.length >= 3) {
            this.hashs = this.hash.slice(0, this.cou);
          }
        }

        if (this.loadingmore2 == 1) {
          if (this.listPrivilegedata.length >= 3) {
            this.listPrivilegedatas = this.listPrivilegedata.slice(0, this.cou);
          }
        }
      });
    },
    handCloseDetail() {
      this.viewOpen = false;
      this.showData = [];
    },
    getNumber(k, i, idx) {
      i = parseInt(i)
      k = parseInt(k)
      if (i > k) {
        this.infoList[idx].giftsNumber = 1
        this.msgError("赠品数不能大于赠品总数");
      }
    },
    getCouponNumber(k, i, idx) {
      i = parseInt(i)
      k = parseInt(k)
      if (i > k) {
        this.infoList2[idx].couponNumber = 1
        this.msgError("赠送数不能大于优惠券总数");
      }
    },
    //跳转自定义权益
    skipPrivileage() {
      this.$router.push("/privilege/data/");
    },
    /** 提交按钮 */
    submitForm() {
      let errCount = 0;
      this.checkExceptRisk.forEach((item) => {
        if (item.platformUnit != null && item.privilegeStatus == true) {
          console.log(item);
          let value = item.privilegeValue;
          let reg = "";
          let msg = "";
          if (item.privleageName != "points") {
            reg = /^((0\.[1-9]{1})|(([1-9]{1})(\.\d{1})?))$/;
            msg = item.privleageShowName + ":输入错误,请输入整数或小数后一位";
          } else {
            reg = /^[0-9]{1,8}$/;
            msg = item.privleageShowName + ":输入错误,请输入八位整数";
          }
          if (!reg.test(value)) {
            errCount++;
            this.$message.error(msg);
          }
        }
      })

      if (this.paymentRuless.length == 0) {
        errCount++;
        return this.$message.error("付费规则不能为空");
      }else {
        const reg = /^\d*\.{0,1}\d{0,1}$/;
        if (!reg.test(this.paymentRuless[0].price)) {
          errCount++;
          this.$message.error("价格请输入整数或小数后一位");
        }
      }
      if (errCount == 0) {
        this.$refs["form"].validate((valid) => {
          if (valid) {
            let CustomerLevelVo = this.form;
            CustomerLevelVo.directPointsPoints = this.form.directPointsPointsStr;
            CustomerLevelVo.indirectPointsPoints = this.form.indirectPointsPointsStr;
            CustomerLevelVo.selfbuyPointsPoints = this.form.selfbuyPointsPointsStr;
            CustomerLevelVo.customerPattern = 1;
            let caedFace = this.form.caedFace;
            if (caedFace == undefined) {
              caedFace = '0';
            }
            CustomerLevelVo.caedFace = caedFace;
            if (
              CustomerLevelVo.levelColor == null &&
              CustomerLevelVo.levelColor == "" &&
              CustomerLevelVo.levelImage == null &&
              CustomerLevelVo.levelImage == ""
            ) {
              CustomerLevelVo.levelColor = "#87CEEB";
            }
            if (CustomerLevelVo.caedFace == 0) {
              CustomerLevelVo.levelColor = this.bgcolor;
            } else {
              CustomerLevelVo.levelImage = this.form.levelImage;
            }
            Vue.set(CustomerLevelVo, "paymentRules", this.paymentRuless[0]);
            Vue.set(CustomerLevelVo, "customerPrivileges", this.checkExceptRisk);
            let giveobjs = new Array();
            let giveobjs2 = new Array();
            CustomerLevelVo.customerPrivileges.forEach((item) => {
              if (item.privleageName == "gift") {
                if (item.isGive == "1" && item.privilegeStatus == true) {
                  let privleageName = item.privleageName;
                  this.infoList.forEach((infoItem) => {
                    let giveobj = new Object();
                    giveobj.giveName = infoItem.giftName;
                    giveobj.giveGiftId = infoItem.giftUid;
                    giveobj.giveNumber = infoItem.giftsNumber;
                    giveobj.giveSumNumber = infoItem.stockNumber;
                    giveobj.giveType = privleageName;
                    giveobjs.push(giveobj);
                  });
                  Vue.set(item, "levelPrivileageGives", giveobjs);
                }
              }
            });
            CustomerLevelVo.customerPrivileges.forEach((item) => {
              if (item.privleageName == "coupon") {
                console.log(item, '1302');
                if (item.isGive == "1" && item.privilegeStatus == true) {
                  let privleageName = item.privleageName;
                  this.infoList2.forEach((i) => {
                    let giveobj2 = new Object();
                    giveobj2.giveName = i.couponTypeName;
                    giveobj2.giveGiftId = i.couponUid;
                    giveobj2.giveNumber = i.couponNumber;
                    giveobj2.giveSumNumber = i.stock;
                    giveobj2.giveType = privleageName;
                    giveobjs2.push(giveobj2);
                    console.log(giveobjs2, '1313');
                  });
                  Vue.set(item, "levelPrivileageGives", giveobjs2);
                }
              }
            });
            if (this.form.levelId != null) {
              console.log(CustomerLevelVo, '修改数据');
              UpdateLevelPrivileageInfo(CustomerLevelVo).then((response) => {
                this.msgSuccess("修改成功");
                CustomerLevelVo = null
                this.open = false;
                this.colseLevel();
              });
            } else {
              let Privileges = new Array();
              CustomerLevelVo.customerPrivileges.forEach((item) => {
                if (item.privilegeStatus == true) {
                  Privileges.push(item);
                }
              });
              CustomerLevelVo.customerPrivileges = [];
              Privileges.forEach((item) => {
                CustomerLevelVo.customerPrivileges.push(item);
              });
              console.log(CustomerLevelVo, '添加数据');
              saveLevelPrivileageInfo(CustomerLevelVo).then((response) => {
                this.msgSuccess("新增成功");
                CustomerLevelVo = null
                this.open = false;
                this.colseLevel();
              });
            }
          }
        });
      }
    },
    // 取消按钮
    Formcancel() {
      this.colseLevel();
    },
    colseLevel() {
      this.$store.dispatch("tagsView/delView", this.$route);
      this.$router.push({
        path: "/customer/level",
        query: {
          t: Date.now()
        }
      });
    }
  }
};
</script>
<style lang="less" scoped>
#container {
  width: 100%;
  height: 50%;
}

#photo {
  float: left;
  width: 70%;
}

#content {
  float: right;
  width: 30%;
}

.product-header {
  font-size: 18px;
  margin-bottom: 20px;
}

.product-div {
  background-color: #fff;
  position: relative;
  padding: 30px;
  border: 1px solid #eee;
  border-radius: 10px;
  width: 1200px;
  margin: 30px auto;
}

.product-div-two {
  background-color: #fff;
  position: relative;
  padding: 20px;
  border: 1px solid #eee;
  border-radius: 10px;
  width: 1200px;
  margin: 30px auto 100px;
}

.place-font {
  color: #999;
  font-size: 13px;
  position: relative;
}

.dw {
  position: fixed;
  bottom: 0;
  z-index: 10;
  left: 0;
  width: 100%;
  height: 68px;
  padding-left: 120px;
  box-shadow: 0 -2px 8px rgb(200 201 204 / 20%);
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
}

.div-img {
  display: none;
}

.div-text {
  margin: 22px 0px 12px 120px;
  color: #2656bd;
  cursor: pointer;
  font-size: 13px;
}

.bgcard {
  width: 340px;
  height: 180px;
  border-radius: 15px;
  position: absolute;
  top: 15%;
  right: 5%;
}

.font-a {
  font-size: 22px;
  font-weight: 900;
  color: #ffffff;
  margin: 20px 0 0 20px;
}

.font-b {
  font-size: 12px;
  color: #ffffff;
  margin: 0px 0 0 20px;
}

.font-b span {
  font-size: 24px;
  font-weight: 700;
}

.font-c {
  width: 89%;
  border: 1px solid #fff;
  margin: 20px 0 0 20px;
}

.itemyanse {
  width: 100%;
  height: 100%;
  display: flex;
  flex: 1;
  margin-top: 5px;
}

.bgyanse {
  width: 20%;
  margin-right: 5px;
}

// .elradio {
//   margin-top: 12px;
// }
.formitem {
  width: 100%;
  height: 100%;
  position: relative;
  top: -30px;
}

.formitem-p {
  font-size: 20px;
}

.qy {
  font-size: 20px;
}

.Unitdiv {
  display: inline-block;
  width: 30px;
  height: 29px;
  border-left: 1px solid #dcdee0;
  border-right: 1px solid #dcdee0;
  position: relative;
  top: 0;
  right: 31px;
  background-color: #f7f8fa;
  text-align: center;
  line-height: 29px;
}

.el-input {
  width: 120px;
}

.selectgift {
  margin-top: 10px;
}

.el-checkbox {
  margin-bottom: 10px;
}

.GiftBag {
  position: relative;
}

.inputcolumn {

  // position: absolute;
  // top: 10px;
  // right: 25px;
  // margin-left: 80%;
  .el-input {
    width: 60px;
  }
}

.el-checkbox {
  width: 70px;
}

.couponGift {
  width: 100px;
  height: 30px;
  font-size: 14px;
  color: rgb(0, 175, 255);
}

.block {
  padding: 30px 0;
  text-align: center;
  display: inline-block;
  vertical-align: top;
  margin-top: 1%;
  margin-left: -9%;
}

.app-container {
  background-color: #F7F8FA;
  padding: 20px;
}

.font-normal1 {
  font-size: 12px;
  color: #84868a;
  margin-top: -5px;
}

.font-normal {
  font-size: 12px;
  color: #84868a;
  margin-top: -6px;
}

.div-title {
  background-color: rgb(242, 246, 252);
  margin: 15px;
  padding: 10px 10px 10px 10px;
}

.descText {
  color: var(--theme-stroke-3, #969799);
  line-height: 14px;
  font-size: 12px;
  margin-top: 10px;
  margin-bottom: 0;
}

.titleText {
  line-height: 14px;
  font-size: 14px;
  margin-top: 10px;
  margin-bottom: 0;
}

.channelClass {
  border: 1px solid #e5e5e5;
  padding: 20px;
  width: 450px;
  height: 300px;
  float: left;
  margin-left: 20px;
  margin-top: 20px;
}

.channelConten {
  border: 1px dotted #e5e5e5;
  padding: 25px 10px;
  height: 170px;
  text-align: center;
  min-height: 110px;
  box-sizing: border-box;
  display: -ms-flexbox;
  display: flex;
  margin-top: 10px;
  -ms-flex-align: center;
  align-items: center;
  -ms-flex-pack: center;
  justify-content: center;
}

.descIcon {
  font-size: 40px;
  line-height: 40px;
  font-weight: 200;
  color: #155bd4;
}

// .el-input {
//   width: 200px;
// }

/deep/ .el-upload--picture-card {
  width: 60px;
  height: 60px;
}

/deep/ .el-upload {
  width: 60px;
  height: 60px;
  line-height: 60px;
  margin-top: 10px;
}

/deep/ .el-upload-list--picture-card .el-upload-list__item {
  width: 60px;
  height: 60px;
  line-height: 60px;
}

/deep/ .el-upload-list--picture-card .el-upload-list__item-thumbnail {
  width: 60px;
  height: 60px;
  line-height: 60px;
}

/deep/ .avatar {
  width: 60px;
  height: 60px;
}

.el-icon-plus {
  font-size: 14px;
}
</style>
